package qc.module.platform.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.platform.dto.param.log.ParamValueLogQueryConditionDto;
import qc.module.platform.dto.param.log.ParamValueLogQueryResultDto;
import qc.module.platform.dto.param.value.ObjectParamValuesDto;
import qc.module.platform.dto.param.value.ParamValuesGetConditionDto;
import qc.module.platform.dto.param.value.ParamValuesQueryResultDto;
import qc.module.platform.dto.param.value.ParamValuesSaveDto;
import qc.module.platform.service.ParamValueService;

import java.sql.SQLException;
import java.util.List;

/**
 * 参数值控制器，用于维护、查询、获取参数值
 *
 * @author QuCheng Tech
 * @since 2024/2/21
 */
@RestController
@RequestMapping("/paramvalue")
public class ParamValueController {
    private ParamValueService paramValueService;

    @Autowired
    public void setParamValueService(ParamValueService paramValueService) {
        this.paramValueService = paramValueService;
    }

    /***
     * 查询指定参数分组的参数值
     *
     * @param id 参数分组ID
     * @return qc.module.platform.dto.param.value.ParamValuesQueryResultDto
     * @author QuCheng Tech
     * @since 2024/2/21
     */
    @GetMapping("/query")
    public ParamValuesQueryResultDto queryByParam(@RequestParam(name = "id", required = true) String id) throws QCPromptException, SQLException {
        return paramValueService.queryByGroupId(id);
    }

    /***
     * 查询指定参数分组的参数值
     *
     * @param id 参数分组ID
     * @return qc.module.platform.dto.param.value.ParamValuesQueryResultDto
     * @author QuCheng Tech
     * @since 2024/2/21
     */
    @GetMapping("/query/{id}")
    public ParamValuesQueryResultDto queryByPath(@PathVariable(name = "id", required = true) String id) throws QCPromptException, SQLException {
        return paramValueService.queryByGroupId(id);
    }

    /***
     * 保存参数值
     *
     * @param dto 保存的对象，指定参数分组ID、对象参数值集合
     * @return java.lang.String
     * @author QuCheng Tech
     * @since 2024/2/21
     */
    @PostMapping("/save")
    public String save(@RequestBody ParamValuesSaveDto dto) throws QCPromptException, SQLException {
        return paramValueService.save(dto);
    }

    /***
     * 获取参数值信息
     *
     * @param condition 获取条件，指定分组ID、对象编码、参数编码；根据标记是否返回参数项信息
     * @return qc.module.platform.dto.param.value.ParamValuesQueryResultDto
     * @author QuCheng Tech
     * @since 2024/2/21
     */
    @RequestMapping(value = "/get", method = {RequestMethod.POST, RequestMethod.GET})
    public List<ObjectParamValuesDto> get(@RequestBody ParamValuesGetConditionDto condition) throws QCPromptException, SQLException {
        return paramValueService.getValues(condition);
    }

    /***
     * 查询参数值日志记录
     *
     * @param condition 查询条件，指定分组ID、对象编码、参数编码
     * @return qc.module.platform.dto.param.log.ParamValueLogQueryResultDto
     * @author QuCheng Tech
     * @since 2024/2/21
     */
    @RequestMapping(value = "/log", method = {RequestMethod.POST, RequestMethod.GET})
    public ParamValueLogQueryResultDto queryLogs(@RequestBody ParamValueLogQueryConditionDto condition) throws QCPromptException, SQLException {
        return paramValueService.queryLogs(condition);
    }
}
